<template>
  <div>
    <span>用户名:</span><input type="text" v-model="obj.username" />
    <span>密码:</span><input type="password" v-model="obj.password" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      obj: {
        username: "",
        password: "",
      },
    };
  },
  watch: {
    /* username(newVal, oldVal) {
      console.log(newVal, oldVal);
    }, */
    obj: {
      handler(newVal, oldVal) {
        console.log(newVal);
        console.log(oldVal);
      },
      deep: true, //深度侦听   true为开启状态(对象里面的属性发生改变的时候,会触发handler函数)
      immediate: true, //立即侦听  网页刚打开就会出发一次 立即侦听
    },
  },
};
</script>

<style></style>
